import { Limits, ServerTags } from '@boticord/consts'
import {
  ArrayMaxSize,
  ArrayMinSize,
  IsArray,
  IsIn,
  IsOptional,
  MaxLength,
  IsString, IsUrl, Length,
  ValidateNested, IsBoolean, IsInt,
} from 'class-validator'
import { enumToValues } from '@boticord/common'
import { PremiumServerDto } from './premium-server.dto'
import { Type } from 'class-transformer'

export class UpdateServerDto {
  @IsString()
  @MaxLength(Limits.MaxResourceDescriptionLength)
  declare description: string

  @IsString()
  @MaxLength(Limits.MaxResourceShortDescriptionLength)
  declare shortDescription: string

  @IsString()
  @IsUrl({
    host_whitelist: [ 'discord.gg' ],
    require_host: true,
    require_protocol: true,
    protocols: [ 'https' ],
  })
  @Length(Limits.MinSupportServerInviteLength, Limits.MaxSupportServerInviteLength)
  declare inviteLink: string

  @IsArray()
  @ArrayMaxSize(enumToValues(ServerTags).length)
  @ArrayMinSize(Limits.MinTags)
  @IsIn(enumToValues(ServerTags), { each: true })
  declare tags: number[]

  @IsOptional()
  @IsBoolean()
  declare premiumActive?: boolean

  @IsOptional()
  @ValidateNested()
  @Type(() => PremiumServerDto)
  declare premium?: PremiumServerDto

  @IsOptional()
  @IsArray()
  @ArrayMaxSize(Limits.MaxModerators)
  @Length(Limits.MinDiscordIdLength, Limits.MaxDiscordIdLength, { each: true })
  declare moderators?: string[]

  @IsOptional()
  @IsInt()
  declare standardBannerID?: number
}
